use std::fmt::{Display, Debug};
//---------------------------------------------------------------
#[allow(dead_code)]
trait PrintInOption {
    fn print_in_option(self);
}
#[allow(dead_code)]
impl<T> PrintInOption for T  where T: Debug {
    fn print_in_option(self) {
        println!("{:?}", Some(self));
    }
}
// ---------------------------------------------------------------
#[allow(dead_code)]
fn  compare_prints<T: Display + Debug>(t: &T) {
    println!("Debug:`{:?}`", t);
    println!("Display:`{}`", t);
}
#[allow(dead_code)]
fn compare_types<T: Debug, U: Debug>(t: &T, u: &U) {
    println!("Debug:`{:?}`", t);
    println!("Debug:`{:?}`", u);
}
// ---------------------------------------------------------------
// 获取基本类型和自定义类型之间的转换， years.0 代表 years 结构体的第一个字段，即年数，是基本类型
struct Years(i64);
struct Days(i64);
impl Years {
    fn to_days(&self) -> Days {
        Days(self.0 * 365)
    }
}
impl Days {
    fn to_years(&self) -> Years {
        Years(self.0 / 365)
    }
}
fn is_adult(age: &Years) -> bool {
    age.0 >= 18
}
fn main() {
    // let string = "words";
    // let array = [1, 2, 3];
    // let vec = vec![1, 2, 3];

    // compare_prints(&string);
    // compare_types(&array, &vec);
    // compare_prints(&array);

    // let vec = vec![1, 2, 3];
    // vec.print_in_option();

    let age = Years(25);
    let age_days = age.to_days();
    println!(" Is an adult? {}", is_adult(&age));
    println!(" Is an adult? {}", is_adult(&age_days.to_years()));
    // println!(" Is an adult? {}", is_adult(&age_days));
}